
function Counties(map) {

    this.getInfoWindowHtml = function(rec) {
	var html = "<table>";
	html += "<tr><td>County Name: <td>" + rec[1];
	html += "<tr><td>State: <td>" + rec[2];
	html += "<tr><td>Time Zone: <td>" + rec[3];
	html += "</table>";
	return html;
    };
    this.openInfoWindow = function(e, rec) {
	if (this.openTimeout) {
	    clearTimeout(this.openTimeout);
	}
	this.openTimeout = setTimeout(function(rec) {
		var html = this.getInfoWindowHtml(rec);
		var x = e.pageX;
		var y = e.pageY;
		title = rec[1]
		if (this.infowindow) {
		    //x = this.infowindow.getPosition()[0];
		    //y = this.infowindow.getPosition()[1];
		    this.infowindow.close();
		}
		this.infowindow = new Ext.Window({
			//width: 250,
			title:title,
			closeAction: 'close',
			items:[{
				html:html
			    }]
		    });
		this.infowindow.on('close',function(){this.infowindow = false;}.createDelegate(this));
		this.infowindow.setPosition(x+15,y+15);
		this.infowindow.show();
	    }.createDelegate(this,[rec]),500);
    };
    this.closeInfoWindow = function(rec) {
	if (this.openTimeout) {
	    clearTimeout(this.openTimeout);
	}
	if (this.closeTimeout) {
	    clearTimeout(this.closeTimeout);
	}
	if (this.infowindow) {
	    //this.closeTimeout = setTimeout(function(){this.infowindow.close();this.closeTimeout = false;}.createDelegate(this),5000);
	}
    };


    this.map = map;
    this.gref = new SAPolyOverlay({
	    map:this.map,
	    url_prefix:"/icounties",
 	    mouseover:this.openInfoWindow.createDelegate(this),
	    mouseout:this.closeInfoWindow.createDelegate(this)
	});
    this.gref.setOpacity(.5);
}

function initialize() {
    var myLatlng = new google.maps.LatLng(40.05,-105.37);
    var myOptions = {
	zoom: 8,
	center: myLatlng,
	mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("mapDiv"), myOptions);
    var counties = new Counties(map);
}
